<template>
	<section>
		<full-screen-dialog :title="titleMap[mode]" v-model="visible" :width="1200" destroy-on-close @closed="$emit('closed')">
			<el-form :disabled="mode == 'Show'" ref="dialogForm" label-width="100px">
			<el-descriptions :column="4">
				<el-descriptions-item label="下单日期">{{entityObj.storageOrderTime}}</el-descriptions-item>
				<el-descriptions-item label="单据编号">{{entityObj.storageOrderCode}}</el-descriptions-item>
				<el-descriptions-item label="客户">{{entityObj.storeName}}</el-descriptions-item>
				<el-descriptions-item label="业务员">{{entityObj.salesman}}</el-descriptions-item>
				<el-descriptions-item label="制单人">{{entityObj.documentsUser}}</el-descriptions-item>
				<el-descriptions-item label="关联要货单">{{entityObj.applyOrderCode}}</el-descriptions-item>
			</el-descriptions>
			<el-table :data="listData" :border="true" style="width: 100%" show-summary>
				<el-table-column label="物料编码" prop="materialCode">

				</el-table-column>
				<el-table-column label="物料名称" prop="materialName">

				</el-table-column>
				<el-table-column label="规格型号" prop="materialSpecs">

				</el-table-column>
				<el-table-column label="厂家名称" width="200" prop="supplierFullName">

				</el-table-column>
				<el-table-column prop="qty" label="数量">
					<template #default="scope">
						<el-input-number v-model="scope.row.qty" style="width: 100%" :step="1"
							controls-position="right"></el-input-number>
					</template>
				</el-table-column>
				<el-table-column label="单价">
					<template #default="scope">
						<el-input-number v-model="scope.row.price" style="width: 100%" :step="1"
							controls-position="right"></el-input-number>
					</template>
				</el-table-column>
				<el-table-column label="单位" prop="unitName">

				</el-table-column>
				<el-table-column label="备注">
					<template #default="scope">
						<el-input v-model="scope.row.remarks" />
					</template>
				</el-table-column>
			</el-table>
			</el-form>

			<!-- <el-form :model="entityObj" :rules="rules" :disabled="mode == 'Show'" ref="dialogForm" label-width="100px">

			</el-form> -->
			<template #footer>
				<div style="text-align: center;">
					<el-button @click="visible = false">关 闭</el-button>
					<el-button type="primary" v-if="mode != 'Show'" @click="submit()">保存</el-button>
				</div>

			</template>
		</full-screen-dialog>
	</section>
</template>

<script>
	import tool from "@/utils/tool";
	export default {
		emits: ["success", "closed"],
		data() {
			return {
				mode: "Check",
				titleMap: {
					Check: "核对",
					Show: "物料明细",
				},
				visible: false,
				entityObj: {},
				rules: {},
				listData:[]
			}
		},
		methods: {
			//显示=
			open(mode = "Check") {
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单注入数据
			async setData(data) {
				console.log(data)
				try {
					this.entityObj = data
					let arr = []
					arr.push(data)
					this.listData = arr
					console.log(this.entityObj);


				} catch (error) {
					this.loading = false;
					return false;
				}
			},
			async submit(){
				let obj = {}
				obj.storageOrderId = this.entityObj.storageOrderId
				obj.price = this.entityObj.price
				obj.qty = this.entityObj.qty
				obj.totalAmount = this.entityObj.totalAmount
				obj.remarks = this.entityObj.remarks

				const returnValue = await this.$API.auth.PostProcessApi.post(
				    "storage-order/check",
				    obj
				);
				if (returnValue.status == 200) {
					this.$message.success(returnValue.msg);
					this.$emit("fatherMethod");
					this.visible = false;
				} else {
				    this.$message.error("操作失败:" + returnValue.msg);
				}
			}
		}
	}
</script>

<style scoped>
</style>
